<template>
	<view style="background: #f6f6f8;width: 100%;height: 100vh;">
		<view v-if="orderList.length>0">
			<view class="tbc-flex-col" v-for="(item, index) in orderList" :key="index">
				<orderItem :item="item" @refreshOrder="refreshOrder"></orderItem>
			</view>
		</view>
		<view class="blank_box" v-else>
			<view>No order</view>
		</view>
	</view>
</template>

<script>
  import SellOutIndex from '../sell/sellOutIndex.vue';
import orderItem from './stockItem.vue';
	export default {
		components: {orderItem},
		data() {
			return {
				orderList: [],
				total: -1,
				page: 1,
				inRequest: false,
				refresh: 0,
				totalPrice:0,
        standing:0,
			}
		},
		computed: {
		},
		onLoad: function(options) {
		},
		onShow() {
      this.standing = uni.getStorageSync("standing")
      //仓库2 店铺3
      this.getOrderList()
		},
		onPullDownRefresh: function() {
      this.page=1
			this.initOrderList()
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom: function() {
			this.getOrderList()
		},
		methods: {
      refreshOrder(){
        this.page=1
        this.initOrderList()
        setTimeout(function() {
          uni.stopPullDownRefresh();
        }, 1000);
      },
			async handleDelOrders(){
				let list=this.orderList.filter(v=>v.checked)
				let ids=list.map(v=>{
					return v.id
				})
				const res = await uni.$http.post('/order/del',{order_ids:ids})
				if (res.data.code !== 200) {
					return uni.showToast({
						title: res.data.msg,
						icon: 'none'
					})
				}else{
					this.getOrderList()
				}
			},
			selectOrderIds(orders){
				let item=this.orderList[orders.order_index]
				this.orderList[orders.order_index].checked=!item.checked
				let list=this.orderList.filter(v=>v.checked)
				let price_list=list.map(v=>{
					return v.pay_money
				})
				this.totalPrice=price_list.reduce((a,b)=>parseFloat(a)+parseFloat(b))
			},
			async initOrderList() {
				this.page = 1
				this.total = -1
				this.orderList=[]
				this.getOrderList()
			},
			async getOrderList() {
        if(this.standing==2){
          this.$ajax(this.$http + '/store/storegGoodsSkus?page='+this.page+'&per_page=10', "GET", null, (response) => {
            let data = JSON.parse(response)
						if(data.data.is_next_page){
							let list=data.data.list.filter(v=>v.sku_stock>0)
							this.orderList = [...this.orderList,...list]
						}else{
							uni.showToast({
								title: "no more...",
								icon: "none"
							})
						}
          })
        }else{
          this.$ajax(this.$http + '/stock/list?page='+this.page+'&per_page=10', "GET", null, (response) => {
            let data = JSON.parse(response)
						if(data.data.is_next_page){
							let list=data.data.list.filter(v=>v.sku_stock>0)
							this.orderList = [...this.orderList,...list]
						}else{
							uni.showToast({
								title: "no more...",
								icon: "none"
							})
						}
          })
        }
			},
			stopPullDownRefresh() {
				// #ifdef APP-NVUE
				this.$refs.list.stopPullDownRefresh()
				// #endif
				uni.stopPullDownRefresh()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.blank_box {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-bottom: 400rpx;
		background: #fff;

		.blank_icon {
			width: 50%;
			margin-top: 200rpx;
			margin-bottom: 40rpx;
		}
	}
</style>